﻿using QFramework;
using UnityEngine;

namespace ProjectIndieFarm
{
    public class ToolWateringPot : ITool
    {
        public string Name => "water_pot";

        public int Range => Global.PlantActionRange;

        public float TimeCost => Global.ToolHourCostWaterPot;

        public float ActionDuration => 0.5f * (Global.ToolHourCostWaterPot / Config.INIT_TOOL_HOUR_COST_WATER_POT);

        public bool Selectable(ToolData data)
        {
            return Global.CurrentTool.Value.Name.Equals(Name)
                        && data.SoilGrid[data.CellPosition.x, data.CellPosition.y] != null
                        && data.SoilGrid[data.CellPosition.x, data.CellPosition.y].Watered == false;
        }

        public void Use(ToolData data)
        {
            var gridController = Object.FindObjectOfType<GridController>();
            gridController.Water.SetTile(new Vector3Int(data.CellPosition.x, data.CellPosition.y), gridController.WaterTile);
            data.SoilGrid[data.CellPosition.x, data.CellPosition.y].Watered = true;

            AudioController.Instance.SfxWatering.Play();

            var toolController = Object.FindObjectOfType<ToolController>();
            var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            toolController.WaterFx.Position(mousePos.x, mousePos.y);
            toolController.WaterFx.GetComponent<ParticleSystem>().Play();
            CameraController.ShakeSlight();
        }
    }
}
